package com.whz.serial;

import com.google.common.collect.ImmutableList;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @ClassName Name
 * @Description TODO 仅仅表示人名的类,默认的序列化形式就是合理的
 * 如果一个对象的物理表示法等同于它的逻辑内容,可能就适合于使用默认的序列化形式
 * @serial 标签告诉Javadoc工具,把这些文档信息放在有关序列化形式的特殊文档页中
 * @Author hong-zhi
 * @Date 2021/5/26 16:54
 * @Version 1.0
 */
@Slf4j
public class Name implements Serializable {
    
    /**
     * 名字
     * 不能为空
     * @serial
     */
    private transient final String lastName;
    private transient final String middleName;
    private transient final String firstName;

    public Name(String lastName, String middleName, String firstName) {
        this.lastName = lastName;
        this.middleName = middleName;
        this.firstName = firstName;
    }

    private void writeObject(ObjectOutputStream s) throws IOException {
        s.defaultWriteObject();
        s.writeObject(List.of(this.firstName, this.middleName, this.lastName));
    }
    private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
        s.defaultReadObject();
        Object nameObj = s.readObject();
        @SuppressWarnings("uncheck")
        List<String> nameList = (List<String>)Objects.requireNonNull(nameObj);
        nameList.stream().forEach(System.out::println);
    }

}
